package com.shux.common.action;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.shux.utils.other.Response;
import com.shux.utils.other.UuidUtil;
import com.shux.utils.page.Page;
import com.shux.utils.page.PageData;

/**
 **********************************************
 *  描述：
 * Simba.Hua
 * 2017年5月25日
 **********************************************
**/
public class BaseAction {


    protected Logger logger = LoggerFactory.getLogger(getClass());


    /**
     * new PageData对象
     * 
     * @return
     */
    public PageData getPageData() {
      return new PageData(this.getRequest());
    }

    /**
     * 得到ModelAndView
     * 
     * @return
     */
    public ModelAndView getModelAndView() {
      return new ModelAndView();
    }

    /**
     * 得到request对象
     * 
     * @return
     */
    public HttpServletRequest getRequest() {
      HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
          .getRequestAttributes()).getRequest();
      return request;
    }

    /**
     * 得到32位的uuid
     * 
     * @return
     */
    public String get32UUID() {
      return UuidUtil.get32UUID();
    }

    /**
     * 得到分页列表的信息
     * 
     * @return
     */
    public Page getPage() {
      return new Page();
    }

    public static void logBefore(Logger logger, String interfaceName) {
      logger.info("");
      logger.info("start");
      logger.info(interfaceName);
    }

    public static void logAfter(Logger logger) {
      logger.info("end");
      logger.info("");
    }
    
    
    
    /**
     * 返回json格式的数据
     */
    public Response returnResult(boolean result,String message){
      Response m = new Response();
      m.setResult(result);
      m.setMessage(message);
      return m;
    }
    
}
